﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XZL.GM.Bll;
using XZL.GM.Dal;

public partial class Course_CourseCount : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindCourseTypeList();
            txtCourseStart.Text = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
            txtCourseEnd.Text = DateTime.Now.ToString("yyyy-MM-dd");
         
            BindCourseCount();
        }
    }


    private void BindCourseCount()
    {

        DateTime courseStart = new DateTime();
        DateTime courseEnd = new DateTime();
        var type =Convert.ToInt16(hfType.Value);
        try
        {
            courseStart = Convert.ToDateTime(txtCourseStart.Text);
            courseEnd = Convert.ToDateTime(txtCourseEnd.Text);
            courseEnd = courseEnd.AddDays(1);
        }
        catch (Exception ex)
        {
            //  lblWarn.Text = "请输入正确的日期格式！";
            return;
        }
        int? count = 0;
        int courseType = Convert.ToInt32(ddlCourseType.SelectedValue);
        divCondition.Visible = true;
        gridList.DataSource = CourseInfoBiz.GetCourseCount(type, txtCourseName.Text.Trim(), courseType, courseStart, courseEnd, netPager.CurrentPageIndex, netPager.PageSize, ref count);
        gridList.DataBind();
        netPager.RecordCount = count.Value;


    }


    private void BindCourseTypeList()
    {
        ddlCourseType.DataSource = CourseInfoBiz.GetCourseTypeList();
        ddlCourseType.DataValueField = "CourseTypeID";
        ddlCourseType.DataTextField = "CourseTypeName";
        ddlCourseType.DataBind();
        ddlCourseType.Items.Insert(0, new ListItem("全部", "0"));
    }



    /// <summary>
    /// 分页控件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void netPager_PageChanged(object sender, EventArgs e)
    {
        BindCourseCount();
    }

      
    protected void btnSelect_Click(object sender, EventArgs e)
    {
        int _type = Convert.ToInt16(((LinkButton)sender).CommandArgument);
        hfType.Value = _type.ToString();
        BindCourseCount();
    } 



}